Announcement

Collapse
No announcement yet.

Function VarDefine(){

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Function VarDefine(){

    I have 50 variables that need to be defined. I have put all 12 of the program sections into functions and I was wondering if I can put the variable definitions in s function.

    I was thinking of somethingl like

    function varDefine(){
    var num1;
    var num2;
    ...
    }

    function preMain(){
    ...}

    function main(){
    varDefine();
    ...
    }

    Any problems with this idea?

  • #2
    Hi David:

    I think that they would have to be initially declared out side of main() or any other function.... otherwise they are considered as local to that function (e.g. DefineVars()).

    Another option is to use an object to hold all of the variables and your DefineVars() function would actually determine what these variables would be.

    Var myObj = new Object();

    preMain() {

    }

    function DefineVars() {
    myObj.myVar1 = 92;
    myObj.myVar2 = 0;
    myObj.myVar3 = "fred";
    }


    main() {
    DefineVars();
    with (myObj) {
    if (myVar1==92) myVar2 = 7;
    myVar3 = "rick";
    }

    }

    Chris

    Comment


    • #3
      David,

      What you are describing would require a preprossor, which JavaScript (and hance EFS) don't have. Then you could define a preprocessor macro which would be substiuted in before the compile (of course compile is another thing JavaScript doesn't have, as such). These are the trade-off's between a tokenized interprative language and compiled native code.


      Garth
      Garth

      Comment

      Working...
      X